﻿using System.Collections.Generic;
using System.Web.Mvc;
using LeanBoard.Models;
using LeanBoard.ServiceReference1;

namespace LeanBoard.Controllers
{
    class DominoStatuses
    {
        public const string ScheduledStatusKey = "Scheduled";
        public const string AnalysisStatusKey = "Analysis";
        public const string ReadyForAnalysisReviewStatusKey = "Ready for analysis review";
        public const string AnalysisReview = "Analysis review";
        public const string ReadyForDevelopment = "Ready for development";
        public const string DevelopmentStatusKey = "Development";
        public const string DevelopmentDoneStatusKey = "Ready for Code Review";
        public const string ReviewStatusKey = "Code Review";
        public const string ReviewDoneStatusKey = "Ready for Approval";
        public const string TestingStatusKey = "Testing";
        public const string DoneStatusKey = "Done";
    }

    class CSSStatuses
    {
        public const string ScheduledStatusKey = "scheduled";
        public const string AnalysisStatusKey = "analysis";
        public const string AnalysisReadyForReviewStatusKey = "analysisReadyForReview";
        public const string AnalysisReviewStatusKey = "analysisReview";
        public const string ReadyForDevelopmentStatusKey = "readyForDevelopment";
        public const string DevelopmentStatusKey = "development";
        public const string DevelopmentDoneStatusKey = "readyForCodeReview";
        public const string ReviewStatusKey = "codeReview";
        public const string ReviewDoneStatusKey = "readyForApproval";
        public const string TestingStatusKey = "testing";
        public const string DoneStatusKey = "done";
    }

    public class LeanBoardController : Controller
    {
        public ActionResult Index()
        {
            IProvideChangeRequests changeRequestsProvider = new DominoChangeRequestsProvider(); //OfflineChangeRequestsProvider(); for poor man's DI
            ItemsCollection itemsCollection = changeRequestsProvider.GetItemsForTheLeanBoard();
            return View(itemsCollection);
        }

        public ActionResult Development()
        {
            return View(new List<Item>());
        }

        [HttpPost]
        public string Move(Item item)
        {
            eMgrWSP eMgrWsp = new eMgrWSPClient();
            string strstatus = TranslateStatus(item.Status);
            SETSTATUSResponse setstatusResponse = eMgrWsp.SETSTATUS(new SETSTATUSRequest(item.Unid, strstatus));
            return setstatusResponse.SETSTATUSReturn.STATUSRESULTREASON;
        }

        private static string TranslateStatus(string inputStatus)
        {
            Dictionary<string, string> dict = new Dictionary<string, string>();

            dict.Add(CSSStatuses.ScheduledStatusKey, DominoStatuses.ScheduledStatusKey);
            dict.Add(CSSStatuses.AnalysisStatusKey, DominoStatuses.AnalysisStatusKey);
            dict.Add(CSSStatuses.AnalysisReadyForReviewStatusKey, DominoStatuses.ReadyForAnalysisReviewStatusKey);
            dict.Add(CSSStatuses.AnalysisReviewStatusKey, DominoStatuses.AnalysisReview);
            dict.Add(CSSStatuses.ReadyForDevelopmentStatusKey, DominoStatuses.ReadyForDevelopment);
            dict.Add(CSSStatuses.DevelopmentStatusKey, DominoStatuses.DevelopmentStatusKey);
            dict.Add(CSSStatuses.DevelopmentDoneStatusKey, DominoStatuses.DevelopmentDoneStatusKey);
            dict.Add(CSSStatuses.ReviewStatusKey, DominoStatuses.ReviewStatusKey);
            dict.Add(CSSStatuses.ReviewDoneStatusKey, DominoStatuses.ReviewDoneStatusKey);
            dict.Add(CSSStatuses.TestingStatusKey, DominoStatuses.TestingStatusKey);
            dict.Add(CSSStatuses.DoneStatusKey, DominoStatuses.DoneStatusKey);

            return dict[inputStatus];
        }

    }
}
